package com.github.hongkaiwen.rxjava.play.problem1;

import java.util.concurrent.TimeUnit;

public abstract class Base {

    private static long start = System.currentTimeMillis();

    protected final void result(int result){
        System.out.println("result runs on: " + Thread.currentThread().getName());
        long cost = (System.currentTimeMillis() - start)/1000;
        System.out.println(String.format(">> result: %d", result));
        System.out.println(String.format(">> cost: %ds", cost));
        if(cost > 5){
            System.out.println(">> too slow !");
            return;
        }
        if(result != 6){
            System.out.println(">> result is not correct !");
            return;
        }
        System.out.println(">> pass !!!");
    }

    protected final int a(){
        return getParam(1);
    }

    protected final int b(){
        return getParam(2);
    }

    protected final int c(){
        return getParam(3);
    }

    protected final int getParam(int result){
        try {
            TimeUnit.SECONDS.sleep(5);
            System.out.println("abc runs on: " + Thread.currentThread().getName());
            return result;
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

}
